package com.atguigu.juc.study.chapter10.reference;

import java.lang.ref.WeakReference;
import java.util.concurrent.TimeUnit;

/**
 * @author : leimingchao
 * @date Date : 2022年06月19日 19:31
 */
public class WeakReferenceDemo {

    public static void main(String[] args) {

        WeakReference<MyObject> weakReference = new WeakReference<>(new MyObject());
        System.out.println("----gc 内存够用：" + weakReference.get());

        System.gc();

        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("gc after内存够用：" + weakReference.get());
    }
}
